// 获取后端数据
function queryLivingIndex(cityName, callback) {
    var xhr; //定义一个变量,用于存放XMLHttpRequest对象
    if (window.XMLHttpRequest) {
        //创建 Ajax 对象
        xhr = new XMLHttpRequest();
    } else if (window.ActiveXObject) {  // IE浏览器的创建方式
        //创建 Ajax 对象
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    var url = "http://127.0.0.1:8000/livingIndex/q?cityName=" + cityName
    // get方式,配置 Ajax 对象
    xhr.open("get", url, true);

    //接收响应
    xhr.onreadystatechange = function () {  // 设置回调函数
        // 判断异步对象的状态
        if (xhr.readyState == 4) {
            // 判断交互是否成功
            if (xhr.status == 200) {
                // 获取服务器响应的数据
                var res = xhr.responseText;
                // 解析数据,json.parse将转res换成js对象
                res = JSON.parse(res);
                // console.log(res);
                callback(res); // 调用回调函数，并传递响应结果
            }

        }

    }
    xhr.send();
}


// 获取html对象
var li = document.getElementsByClassName("li");

// 处理后端数据，将数据填充到weather.html指定位置
function obtainLivingIndex1() {
    var url1 = window.location.href; // 获取网页url
    var cityName = url1.split("=")[1]; // 根据“=”分割
    cityName = decodeURI(cityName); // 解码成中文


    queryLivingIndex(cityName, function (res) {
        var res1 = res;
        if (res1.code == "200") {
            var data = res1.data;
            data = data[0];
            var suitability;
            var care;

            var dataList = data.感冒指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[0].getElementsByTagName("span")[0].textContent = suitability;
            li[0].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.运动指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[1].getElementsByTagName("span")[0].textContent = suitability;
            li[1].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.过敏指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[2].getElementsByTagName("span")[0].textContent = suitability;
            li[2].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.穿衣指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[3].getElementsByTagName("span")[0].textContent = suitability;
            li[3].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.洗车指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[4].getElementsByTagName("span")[0].textContent = suitability;
            li[4].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.紫外线指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[5].getElementsByTagName("span")[0].textContent = suitability;
            li[5].getElementsByTagName("p")[0].textContent = care;
        } else {
            alert("生活指数查询失败！");
        }
    });
}


// 处理后端数据，将数据填充到weather.html指定位置
function obtainLivingIndex2() {
    var url1 = window.location.href; // 获取网页url
    var cityName = url1.split("=")[1]; // 根据“=”分割
    cityName = decodeURI(cityName); // 解码成中文


    queryLivingIndex(cityName, function (res) {
        var res1 = res;
        if (res1.code == "200") {
            var data = res1.data;
            data = data[1];
            var suitability;
            var care;

            var dataList = data.感冒指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[0].getElementsByTagName("span")[0].textContent = suitability;
            li[0].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.运动指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[1].getElementsByTagName("span")[0].textContent = suitability;
            li[1].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.过敏指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[2].getElementsByTagName("span")[0].textContent = suitability;
            li[2].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.穿衣指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[3].getElementsByTagName("span")[0].textContent = suitability;
            li[3].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.洗车指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[4].getElementsByTagName("span")[0].textContent = suitability;
            li[4].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.紫外线指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[5].getElementsByTagName("span")[0].textContent = suitability;
            li[5].getElementsByTagName("p")[0].textContent = care;
        } else {
            alert("生活指数查询失败！");
        }
    });
}


// 处理后端数据，将数据填充到weather.html指定位置
function obtainLivingIndex3() {
    var url1 = window.location.href; // 获取网页url
    var cityName = url1.split("=")[1]; // 根据“=”分割
    cityName = decodeURI(cityName); // 解码成中文


    queryLivingIndex(cityName, function (res) {
        var res1 = res;
        if (res1.code == "200") {
            var data = res1.data;
            data = data[2];
            var suitability;
            var care;

            var dataList = data.感冒指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[0].getElementsByTagName("span")[0].textContent = suitability;
            li[0].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.运动指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[1].getElementsByTagName("span")[0].textContent = suitability;
            li[1].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.过敏指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[2].getElementsByTagName("span")[0].textContent = suitability;
            li[2].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.穿衣指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[3].getElementsByTagName("span")[0].textContent = suitability;
            li[3].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.洗车指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[4].getElementsByTagName("span")[0].textContent = suitability;
            li[4].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.紫外线指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[5].getElementsByTagName("span")[0].textContent = suitability;
            li[5].getElementsByTagName("p")[0].textContent = care;
        }
        else {
            alert("生活指数查询失败！");
        }
    });
}



// 处理后端数据，将数据填充到weather.html指定位置
function obtainLivingIndex4() {
    var url1 = window.location.href; // 获取网页url
    var cityName = url1.split("=")[1]; // 根据“=”分割
    cityName = decodeURI(cityName); // 解码成中文


    queryLivingIndex(cityName, function (res) {
        var res1 = res;
        if (res1.code == "200") {
            var data = res1.data;
            data = data[3];
            var suitability;
            var care;

            var dataList = data.感冒指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[0].getElementsByTagName("span")[0].textContent = suitability;
            li[0].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.运动指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[1].getElementsByTagName("span")[0].textContent = suitability;
            li[1].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.过敏指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[2].getElementsByTagName("span")[0].textContent = suitability;
            li[2].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.穿衣指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[3].getElementsByTagName("span")[0].textContent = suitability;
            li[3].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.洗车指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[4].getElementsByTagName("span")[0].textContent = suitability;
            li[4].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.紫外线指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[5].getElementsByTagName("span")[0].textContent = suitability;
            li[5].getElementsByTagName("p")[0].textContent = care;
        }
        else {
            alert("生活指数查询失败！");
        }
    });
}



// 处理后端数据，将数据填充到weather.html指定位置
function obtainLivingIndex5() {
    var url1 = window.location.href; // 获取网页url
    var cityName = url1.split("=")[1]; // 根据“=”分割
    cityName = decodeURI(cityName); // 解码成中文


    queryLivingIndex(cityName, function (res) {
        var res1 = res;
        if (res1.code == "200") {
            var data = res1.data;
            data = data[4];
            var suitability;
            var care;

            var dataList = data.感冒指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[0].getElementsByTagName("span")[0].textContent = suitability;
            li[0].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.运动指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[1].getElementsByTagName("span")[0].textContent = suitability;
            li[1].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.过敏指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[2].getElementsByTagName("span")[0].textContent = suitability;
            li[2].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.穿衣指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[3].getElementsByTagName("span")[0].textContent = suitability;
            li[3].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.洗车指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[4].getElementsByTagName("span")[0].textContent = suitability;
            li[4].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.紫外线指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[5].getElementsByTagName("span")[0].textContent = suitability;
            li[5].getElementsByTagName("p")[0].textContent = care;
        }
        else {
            alert("生活指数查询失败！");
        }
    });
}



// 处理后端数据，将数据填充到weather.html指定位置
function obtainLivingIndex6() {
    var url1 = window.location.href; // 获取网页url
    var cityName = url1.split("=")[1]; // 根据“=”分割
    cityName = decodeURI(cityName); // 解码成中文


    queryLivingIndex(cityName, function (res) {
        var res1 = res;
        if (res1.code == "200") {
            var data = res1.data;
            data = data[5];
            var suitability;
            var care;

            var dataList = data.感冒指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[0].getElementsByTagName("span")[0].textContent = suitability;
            li[0].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.运动指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[1].getElementsByTagName("span")[0].textContent = suitability;
            li[1].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.过敏指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[2].getElementsByTagName("span")[0].textContent = suitability;
            li[2].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.穿衣指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[3].getElementsByTagName("span")[0].textContent = suitability;
            li[3].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.洗车指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[4].getElementsByTagName("span")[0].textContent = suitability;
            li[4].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.紫外线指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[5].getElementsByTagName("span")[0].textContent = suitability;
            li[5].getElementsByTagName("p")[0].textContent = care;
        }
        else {
            alert("生活指数查询失败！");
        }
    });
}



// 处理后端数据，将数据填充到weather.html指定位置
function obtainLivingIndex7() {
    var url1 = window.location.href; // 获取网页url
    var cityName = url1.split("=")[1]; // 根据“=”分割
    cityName = decodeURI(cityName); // 解码成中文


    queryLivingIndex(cityName, function (res) {
        var res1 = res;
        if (res1.code == "200") {
            var data = res1.data;
            data = data[6];
            var suitability;
            var care;

            var dataList = data.感冒指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[0].getElementsByTagName("span")[0].textContent = suitability;
            li[0].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.运动指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[1].getElementsByTagName("span")[0].textContent = suitability;
            li[1].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.过敏指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[2].getElementsByTagName("span")[0].textContent = suitability;
            li[2].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.穿衣指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[3].getElementsByTagName("span")[0].textContent = suitability;
            li[3].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.洗车指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[4].getElementsByTagName("span")[0].textContent = suitability;
            li[4].getElementsByTagName("p")[0].textContent = care;

            var dataList = data.紫外线指数.split(":");
            suitability = dataList[0];
            care = dataList[1];
            li[5].getElementsByTagName("span")[0].textContent = suitability;
            li[5].getElementsByTagName("p")[0].textContent = care;
        }
        else {
            alert("生活指数查询失败！");
        }
    });
}